<template>
	<view>
		<button @click="load1">请求数据1</button>
		<button @click="load2">请求数据-get</button>
		<button @click="load3">请求数据-post</button>
		<button @click="load4">请求数据-get发送数据给服务器</button>
		<button @click="load5">请求数据-post发送数据给服务器</button>
		<button @click="load6">请求数据-post发送文件给服务器</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			load1() {
				uni.request({
					url: "http://localhost:8080/user/chat",
					method: 'GET',
					success: (res) => {
						console.log(res)
					}
				})
			},
			load2() {
				uni.request({
					url: "http://localhost:8080/chat/v1",
					method:'GET',
					success: (res) => {
						console.log(res)
					}
				})
			},
			load3() {
				uni.request({
					url: "http://localhost:8080/chat/v2",
					method: 'POST',
					success: (res) => {
						console.log(res)
					}
				})
			},
			load4() {
				uni.request({
					url: "http://localhost:8080/chat/v3",
					method: 'GET',
					data: {
						chat_text: '你好'
					},
					success(res) {
						console.log(res)
					}
				})
			},
			load5() {
				uni.request({
					url: "http://localhost:8080/chat/v4",
					method: 'POST',
					data: {
						chat_text: '你好POST'
					},
					success(res) {
						console.log(res)
					}
				})
			},
			load6() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						// console.log(res.tempFilePaths[0])
						this.post_file_server(res.tempFilePaths[0])
					}
				})
			},
			post_file_server(f) {
				console.log(f)
				uni.uploadFile({
					url: "http://localhost:8080/chat/v5",
					method:'POST',
					filePath: f,
					name: 'face',
					success: (res)=>{
						console.log(res)
					}
				})
			}
		}
	}
</script>

<style>

</style>